//未通过 在调试

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF 0x3f3f3f3f
const int maxn = 500 * 2 + 10;
int a[maxn], dp[maxn][maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    a[i] = a[n + i] = k;
  }
  a[0] = a[n];
  a[2 * n + 1] = a[1];
  memset(dp, 0x3f, sizeof(dp));

  for (int i = 1; i <= 2 * n; i++) {
    dp[i][i] = 1 + a[i - 1] + a[i + 1];
  }
  for (int i = 0; i <= 2 * n; i++) {
    for (int j = 0; j <= 2 * n; j++) {
      if (j <= i)
        dp[i][j] = 0;
    }
  }

  for (int len = 2; len <= n; len++)
    for (int i = 1; i <= n; i++) {
      int j = i + len - 1;
      // dp[i][j] = min(dp[i][j], dp[i + 1][j] + 1 + a[i - 1] + a[j + 1]);
      // dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1 + a[i - 1] + a[j + 1]);
      for (int k = i ; k <= j ; k++)
        dp[i][j] = min(dp[i][j],
                       dp[i][k - 1] + dp[k + 1][j] + 1 + a[i - 1] + a[j + 1]);
    }
  int ans = INF;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, dp[i][i + n - 1]);
  }
  cout << ans;
  return 0;
}